package com.omni.monitor.plugin.utils;


import com.alibaba.fastjson.JSONObject;
import org.springframework.http.HttpHeaders;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class EsUtils {

    public static <T> void addEs(String esIndexName, String esUrl, String esToken, List<T> requests) {
        String indexExtName = "-" + LocalDateTime.now().getYear() + "-" + LocalDateTime.now().getMonthValue();
        HttpHeaders header = new HttpHeaders();
        header.set("Content-Type", "application/json");
        header.set("Authentication", esToken);

        String res = SpringHttpUtils.doPostJson(esUrl + esIndexName + indexExtName + "/type/info/bulk/sync", requests, String.class, header);


    }

    public static <T> JSONObject getEsByTemplateName(String esIndexName, String esUrl, String esToken, T requests, String templateName) {
        String indexExtName = "-" + LocalDateTime.now().getYear() + "-" + LocalDateTime.now().getMonthValue();
        HttpHeaders header = new HttpHeaders();
        header.set("Content-Type", "application/json");
        header.set("Authentication", esToken);


        JSONObject res = SpringHttpUtils.doPostJson(esUrl + esIndexName + indexExtName + "/template/" + templateName + "/latest/search", requests, JSONObject.class, header);

        return res;
    }


}
